<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: *');
header('Access-Control-Allow-Credentials: *');

Route::group(['prefix' => 'v1'], function () {

    Route::post('/login', '\Laravel\Passport\Http\Controllers\AccessTokenController@issueToken')
        ->middleware(\App\Http\Middleware\OAuthLogin::class);

    Route::post('/register', 'Api\RegisterController@register');

    Route::post('/sendRegEmail', 'Api\RegisterController@sendRegEmail');

    Route::post("/createTeacher", 'Api\ManagerController@createTeacher');
});

Route::group(['middleware' => 'auth:api', 'prefix' => 'v1'], function () {

    Route::group(['prefix' => 'manager'], function () {
        Route::post("createStudent", 'Api\ManagerController@createStudent');
        Route::post("invite", 'Api\ManagerController@invite');
        Route::get("fans", 'Api\ManagerController@fansList');
    });

    Route::group(['prefix' => 'teacher'], function () {
        Route::get("studentList", 'Api\TeacherController@studentGrid');
        Route::get("likeGrid", 'Api\TeacherController@likeGrid');
    });

    Route::group(['prefix' => 'student'], function() {
        Route::post("like", 'Api\StudentController@like');
        Route::post("cancelLike", 'Api\StudentController@cancelLike');
        Route::get("teacherList", 'Api\StudentController@teacherGrid');
    });

    Route::group(['prefix' => 'users'], function() {
        Route::get("info", 'Api\UserController@info');
    });

    Route::group(['prefix' => 'apply'], function () {
        Route::post("create", 'Api\ApplyController@create');
        Route::get("list", 'Api\ApplyController@list');
    });

    Route::group(['prefix' => 'talk'], function () {
        Route::post("create", 'Api\TalkController@create');
        Route::get("list", 'Api\TalkController@grid');
        Route::get("records", 'Api\TalkController@records');
        Route::post("update-unread-num", 'Api\TalkController@updateUnreadNum');
    });
});

